﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;

namespace Gaea.Oracle
{
    public class GaeaOraclePower : GaeaBasicPower
    {
        private const string _jsonFileName = "appsettings.json";
        private const string _connectionName = "Oracle";

        public static void Register()
        {
            var builder = new ConfigurationBuilder()
           .SetBasePath(Directory.GetCurrentDirectory())
           .AddJsonFile(_jsonFileName).Build();
            var connectionString = builder.GetConnectionString(_connectionName);
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception($"Load connection string fail!Please check [{_connectionName} name in connectionString node");
            }
            Register(connectionString);
        }

        public static void Register(string connectionString)
        {
            var serviceCollection = new ServiceCollection();
            serviceCollection.AddGaeaOracle(connectionString);
            serviceCollection.BuildServiceProvider().UseGaea();
        }

    }
}
